<!DOCTYPE HTML>
<html>
<head>
<title>#SingleInstance | AutoHotkey</title>
<meta name="description" content="The #SingleInstance directive determines whether a script is allowed to run again when it is already running." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#SingleInstance</h1>

<p>决定当脚本已经运行时是否允许它再次运行.</p>

<pre class="Syntax"><span class="func">#SingleInstance</span> <span class="optional">ForceIgnoreOff</span></pre>
<h2>参数</h2>
<dl>

  <dt>ForceIgnoreOff</dt>
  <dd>
    <p>如果省略此参数, 会显示对话框询问是否让旧实例继续运行还是替换为新实例. 要更改此行为, 请指定以下单词之一:</p>
    <p><strong>Force:</strong> 跳过对话框并自动替换旧实例, 效果类似于 <a href="Reload.htm">Reload</a> 命令.</p>  
    <p><strong>Ignore:</strong> 跳过对话框并让旧实例继续运行. 换句话说, 试图启动已经运行的脚本会被忽略.</p>
    <p><strong>Off:</strong> 允许一个脚本同时运行多个实例.</p>
  </dd>

</dl>
<h2>备注</h2>
<p>包含<a href="../Hotkeys.htm">热键</a>, <a href="Hotstrings.htm">热字串</a>, <a href="_Persistent.htm">#Persistent</a>, <a href="OnMessage.htm">OnMessage()</a> 或 <a href="Gui.htm">Gui</a> 的脚本默认是单实例的(重复运行时会显示对话框与提示). 而其他脚本默认允许多个实例. 使用前面描述的方法可以禁用或修改这种行为.</p>
 <p>当使用以下<a href="../Scripts.htm#cmd">命令行开关</a>时, 该指令将被忽略: /force /f /restart /r</p>
<p>AutoHotkey 依赖于脚本<a href="../Program.htm#main-window">主窗口</a>的标题来识别脚本正在运行的其他实例.</p>

<h2>相关</h2>
<p><a href="Reload.htm">Reload</a>, <a href="_Persistent.htm">#Persistent</a></p>
<h2>示例</h2>
<pre class="NoIndent">#SingleInstance force
#SingleInstance ignore
#SingleInstance off</pre>

</body>
</html>